home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / PInterfaces / Threads.p < prev    next >
Encoding:
Text File  |  1995-07-06  |  7.3 KB  |  260 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Threads.p
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.1 in “MPW Latest” on ETO #18
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. }
  19.  
  20. {$IFC UNDEFINED UsingIncludes}
  21. {$SETC UsingIncludes := 0}
  22. {$ENDC}
  23.  
  24. {$IFC NOT UsingIncludes}
  25.  UNIT Threads;
  26.  INTERFACE
  27. {$ENDC}
  28.  
  29. {$IFC UNDEFINED __THREADS__}
  30. {$SETC __THREADS__ := 1}
  31.  
  32. {$I+}
  33. {$SETC ThreadsIncludes := UsingIncludes}
  34. {$SETC UsingIncludes := 1}
  35.  
  36.  
  37. {$IFC UNDEFINED __ERRORS__}
  38. {$I Errors.p}
  39. {$ENDC}
  40. {    ConditionalMacros.p                                            }
  41.  
  42. {$IFC UNDEFINED __MEMORY__}
  43. {$I Memory.p}
  44. {$ENDC}
  45. {    Types.p                                                        }
  46. {    MixedMode.p                                                    }
  47.  
  48. {$PUSH}
  49. {$ALIGN MAC68K}
  50. {$LibExport+}
  51.     
  52. TYPE
  53.     ThreadState = INTEGER;
  54.  
  55.  
  56. CONST
  57.     kReadyThreadState            = 0;
  58.     kStoppedThreadState            = 1;
  59.     kRunningThreadState            = 2;
  60.  
  61. { Error codes have been meoved to Errors.(pah) }
  62. { Thread environment characteristics }
  63.     
  64. TYPE
  65.     ThreadTaskRef = Ptr;
  66.  
  67. { Thread characteristics }
  68.     ThreadStyle = LONGINT;
  69.  
  70.  
  71. CONST
  72.     kCooperativeThread            = 1 * (2**(0));
  73.     kPreemptiveThread            = 1 * (2**(1));
  74.  
  75. { Thread identifiers }
  76.     
  77. TYPE
  78.     ThreadID = LONGINT;
  79.  
  80.  
  81. CONST
  82.     kNoThreadID                    = 0;
  83.     kCurrentThreadID            = 1;
  84.     kApplicationThreadID        = 2;
  85.  
  86. { Options when creating a thread }
  87.     
  88. TYPE
  89.     ThreadOptions = LONGINT;
  90.  
  91.  
  92. CONST
  93.     kNewSuspend                    = 0+(1 * (2**(0)));
  94.     kUsePremadeThread            = 0+(1 * (2**(1)));
  95.     kCreateIfNeeded                = 0+(1 * (2**(2)));
  96.     kFPUNotNeeded                = 0+(1 * (2**(3)));
  97.     kExactMatchThread            = 0+(1 * (2**(4)));
  98.  
  99. { Information supplied to the custom scheduler }
  100.  
  101. TYPE
  102.     SchedulerInfoRec = RECORD
  103.         InfoRecSize:            LONGINT;
  104.         CurrentThreadID:        ThreadID;
  105.         SuggestedThreadID:        ThreadID;
  106.         InterruptedCoopThreadID: ThreadID;
  107.     END;
  108.  
  109.     SchedulerInfoRecPtr = ^SchedulerInfoRec;
  110.  
  111. {$IFC GENERATING68K  & GENERATINGCFM }
  112. {
  113.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  114.     the implementation of the Thread Manager.
  115. }
  116.     ThreadEntryProcPtr = UniversalProcPtr;
  117.  
  118.     ThreadSchedulerProcPtr = UniversalProcPtr;
  119.  
  120.     ThreadSwitchProcPtr = UniversalProcPtr;
  121.  
  122.     ThreadTerminationProcPtr = UniversalProcPtr;
  123.  
  124.     DebuggerNewThreadProcPtr = UniversalProcPtr;
  125.  
  126.     DebuggerDisposeThreadProcPtr = UniversalProcPtr;
  127.  
  128.     DebuggerThreadSchedulerProcPtr = UniversalProcPtr;
  129.  
  130. {$ELSEC}
  131. {
  132.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  133.     of differences between 680x0 and PowerPC runtime architectures with regard to
  134.     the implementation of the Thread Manager.
  135.  }
  136. { Prototype for thread's entry (main) routine }
  137.     voidPtr = Ptr;
  138.  
  139.     ThreadEntryProcPtr = ProcPtr;  { FUNCTION (threadParam: UNIV Ptr): voidPtr; }
  140.  
  141. { Prototype for custom thread scheduler routine }
  142.     ThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  143.  
  144. { Prototype for custom thread switcher routine }
  145.     ThreadSwitchProcPtr = ProcPtr;  { PROCEDURE (threadBeingSwitched: ThreadID; switchProcParam: UNIV Ptr); }
  146.  
  147. { Prototype for thread termination notification routine }
  148.     ThreadTerminationProcPtr = ProcPtr;  { PROCEDURE (threadTerminated: ThreadID; terminationProcParam: UNIV Ptr); }
  149.  
  150. { Prototype for debugger NewThread notification }
  151.     DebuggerNewThreadProcPtr = ProcPtr;  { PROCEDURE (threadCreated: ThreadID); }
  152.  
  153. { Prototype for debugger DisposeThread notification }
  154.     DebuggerDisposeThreadProcPtr = ProcPtr;  { PROCEDURE (threadDeleted: ThreadID); }
  155.  
  156. { Prototype for debugger schedule notification }
  157.     DebuggerThreadSchedulerProcPtr = ProcPtr;  { FUNCTION (schedulerInfo: SchedulerInfoRecPtr): ThreadID; }
  158.  
  159. {$ENDC}
  160.  
  161. FUNCTION CreateThreadPool(threadStyle: ThreadStyle; numToCreate: INTEGER; stackSize: Size): OSErr;
  162.     {$IFC NOT GENERATINGCFM}
  163.     INLINE $303C, $0501, $ABF2;
  164.     {$ENDC}
  165. FUNCTION GetFreeThreadCount(threadStyle: ThreadStyle; VAR freeCount: INTEGER): OSErr;
  166.     {$IFC NOT GENERATINGCFM}
  167.     INLINE $303C, $0402, $ABF2;
  168.     {$ENDC}
  169. FUNCTION GetSpecificFreeThreadCount(threadStyle: ThreadStyle; stackSize: Size; VAR freeCount: INTEGER): OSErr;
  170.     {$IFC NOT GENERATINGCFM}
  171.     INLINE $303C, $0615, $ABF2;
  172.     {$ENDC}
  173. FUNCTION GetDefaultThreadStackSize(threadStyle: ThreadStyle; VAR stackSize: Size): OSErr;
  174.     {$IFC NOT GENERATINGCFM}
  175.     INLINE $303C, $0413, $ABF2;
  176.     {$ENDC}
  177. FUNCTION ThreadCurrentStackSpace(thread: ThreadID; VAR freeStack: LONGINT): OSErr;
  178.     {$IFC NOT GENERATINGCFM}
  179.     INLINE $303C, $0414, $ABF2;
  180.     {$ENDC}
  181. FUNCTION NewThread(threadStyle: ThreadStyle; threadEntry: ThreadEntryProcPtr; threadParam: UNIV Ptr; stackSize: Size; options: ThreadOptions; threadResult: UNIV Ptr; VAR threadMade: ThreadID): OSErr;
  182.     {$IFC NOT GENERATINGCFM}
  183.     INLINE $303C, $0E03, $ABF2;
  184.     {$ENDC}
  185. FUNCTION DisposeThread(threadToDump: ThreadID; threadResult: UNIV Ptr; recycleThread: BOOLEAN): OSErr;
  186.     {$IFC NOT GENERATINGCFM}
  187.     INLINE $303C, $0504, $ABF2;
  188.     {$ENDC}
  189. FUNCTION YieldToThread(suggestedThread: ThreadID): OSErr;
  190.     {$IFC NOT GENERATINGCFM}
  191.     INLINE $303C, $0205, $ABF2;
  192.     {$ENDC}
  193. FUNCTION YieldToAnyThread: OSErr;
  194.     {$IFC NOT GENERATINGCFM}
  195.     INLINE $42A7, $303C, $0205, $ABF2;
  196.     {$ENDC}
  197. FUNCTION GetCurrentThread(VAR currentThreadID: ThreadID): OSErr;
  198.     {$IFC NOT GENERATINGCFM}
  199.     INLINE $303C, $0206, $ABF2;
  200.     {$ENDC}
  201. FUNCTION GetThreadState(threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  202.     {$IFC NOT GENERATINGCFM}
  203.     INLINE $303C, $0407, $ABF2;
  204.     {$ENDC}
  205. FUNCTION SetThreadState(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  206.     {$IFC NOT GENERATINGCFM}
  207.     INLINE $303C, $0508, $ABF2;
  208.     {$ENDC}
  209. FUNCTION SetThreadStateEndCritical(threadToSet: ThreadID; newState: ThreadState; suggestedThread: ThreadID): OSErr;
  210.     {$IFC NOT GENERATINGCFM}
  211.     INLINE $303C, $0512, $ABF2;
  212.     {$ENDC}
  213. FUNCTION SetThreadScheduler(threadScheduler: ThreadSchedulerProcPtr): OSErr;
  214.     {$IFC NOT GENERATINGCFM}
  215.     INLINE $303C, $0209, $ABF2;
  216.     {$ENDC}
  217. FUNCTION SetThreadSwitcher(thread: ThreadID; threadSwitcher: ThreadSwitchProcPtr; switchProcParam: UNIV Ptr; inOrOut: BOOLEAN): OSErr;
  218.     {$IFC NOT GENERATINGCFM}
  219.     INLINE $303C, $070A, $ABF2;
  220.     {$ENDC}
  221. FUNCTION SetThreadTerminator(thread: ThreadID; threadTerminator: ThreadTerminationProcPtr; terminationProcParam: UNIV Ptr): OSErr;
  222.     {$IFC NOT GENERATINGCFM}
  223.     INLINE $303C, $0611, $ABF2;
  224.     {$ENDC}
  225. FUNCTION ThreadBeginCritical: OSErr;
  226.     {$IFC NOT GENERATINGCFM}
  227.     INLINE $303C, $000B, $ABF2;
  228.     {$ENDC}
  229. FUNCTION ThreadEndCritical: OSErr;
  230.     {$IFC NOT GENERATINGCFM}
  231.     INLINE $303C, $000C, $ABF2;
  232.     {$ENDC}
  233. FUNCTION SetDebuggerNotificationProcs(notifyNewThread: DebuggerNewThreadProcPtr; notifyDisposeThread: DebuggerDisposeThreadProcPtr; notifyThreadScheduler: DebuggerThreadSchedulerProcPtr): OSErr;
  234.     {$IFC NOT GENERATINGCFM}
  235.     INLINE $303C, $060D, $ABF2;
  236.     {$ENDC}
  237. FUNCTION GetThreadCurrentTaskRef(VAR threadTRef: ThreadTaskRef): OSErr;
  238.     {$IFC NOT GENERATINGCFM}
  239.     INLINE $303C, $020E, $ABF2;
  240.     {$ENDC}
  241. FUNCTION GetThreadStateGivenTaskRef(threadTRef: ThreadTaskRef; threadToGet: ThreadID; VAR threadState: ThreadState): OSErr;
  242.     {$IFC NOT GENERATINGCFM}
  243.     INLINE $303C, $060F, $ABF2;
  244.     {$ENDC}
  245. FUNCTION SetThreadReadyGivenTaskRef(threadTRef: ThreadTaskRef; threadToSet: ThreadID): OSErr;
  246.     {$IFC NOT GENERATINGCFM}
  247.     INLINE $303C, $0410, $ABF2;
  248.     {$ENDC}
  249.  
  250. {$ALIGN RESET}
  251. {$POP}
  252.  
  253. {$SETC UsingIncludes := ThreadsIncludes}
  254.  
  255. {$ENDC} {__THREADS__}
  256.  
  257. {$IFC NOT UsingIncludes}
  258.  END.
  259. {$ENDC}
  260.